{ inputs
, pkgs
, lib
, config
, options
, ...
}:
{
  env = {
    # The path to the eval cache database (for migrations)
    DATABASE_URL = "sqlite:.devenv/nix-eval-cache.db";

    # The Nix CLI for devenv to use when run with `cargo run`.
    DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix-cli;

    RUST_LOG = "devenv=debug";
    RUST_LOG_SPAN_EVENTS = "full";
  };

  # Configure Claude Code
  claude.code = {
    enable = true;
    commands = {
      release = ''
        Release devenv version $ARGUMENTS

        1. Update version in Cargo.toml to $ARGUMENTS using `cargo set-version`
        2. Run `cargo check` to update Cargo.lock
        3. Generate release notes:
           - Find the latest git tag
           - Get the diff between that tag and HEAD
           - Summarize changes into release notes format
        4. Ask user for access to nixpkgs repository to bump devenv there
           - The package is at pkgs/by-name/de/devenv/package.nix
           - Sync with ./package.nix from this repo and bump version
        5. If this is a major version bump (X.Y.0, not X.Y.Z patch):
           - Generate a blog post in docs/src/blog/posts/
           - Follow the naming convention: devenv-vX.Y-short-description.md
           - Use existing blog posts as reference for format and style
      '';
    };
    permissions = {
      WebFetch = {
        allow = [
          "domain:github.com"
          "domain:docs.rs"
          "domain:docs.anthropic.com"
        ];
      };
      Bash = {
        allow = [
          "rg:*"
          "cargo test:*"
          "nix search:*"
          "devenv-run-tests:*"
          "nix-instantiate:*"
        ];
      };
    };
  };

  # Project dependencies
  packages = [
    pkgs.git
    pkgs.xorg.libxcb
    pkgs.yaml2json
    pkgs.tesh
    pkgs.watchexec
    pkgs.openssl
    pkgs.sqlx-cli
    pkgs.process-compose
    pkgs.cargo-outdated # Find outdated crates
    pkgs.cargo-machete # Find unused crates
    pkgs.cargo-edit # Adds the set-version command
    pkgs.protobuf # snix
    pkgs.dbus # secretspec
  ];

  languages = {
    # For developing the Nix modules
    nix.enable = true;

    # For developing the devenv CLI
    rust.enable = true;
  };

  devcontainer = {
    enable = true;
    settings.customizations.vscode.extensions = [ "jnoortheen.nix-ide" ];
  };

  difftastic.enable = true;

  scripts.devenv-generate-languages-example = {
    description = "Generate an example enabling every supported language";
    exec = ''
      cat > examples/supported-languages/devenv.nix <<EOF
      # DO NOT MODIFY.
      # This file was generated by devenv-generate-languages-example.
      { pkgs, ... }: {

        # Enable all languages tooling!
        ${lib.concatStringsSep "\n  " (
          map (lang: "languages.${lang}.enable = true;") (builtins.attrNames options.languages)
        )}

        # If you're missing a language, please contribute it by following examples of other languages <3
      }
      EOF
    '';
  };

  git-hooks.package = pkgs.prek;
  git-hooks.hooks = {
    nixpkgs-fmt.enable = true;
    rustfmt.enable = true;
    markdownlint = {
      settings.configuration = {
        MD013 = {
          line_length = 120;
        };
        MD033 = false;
        MD034 = false;
      };
    };
  };
}
